"""
CLI движок для Чиори, а также скрипт для запуска проекта.

Author: Milinuri Nirvalen
Ver: 2.4
"""

from backends import vk
from chiori import Chio
from chiori import Config
from chiori import Event
from chiori import Ui
from chiori import load_plugins

import sys
import argparse


class Starter():
	"""CLI движок для Чио."""

	def __init__(self, app: Chio) -> None:
		super(Starter, self).__init__()
		self.name = "Starter"
		self.backend_type = ["cli"]
		self.ver = "2.4"

		self.c = Config(self.name, {"autoclear":True})
		self.__dict__.update(self.c.group_data)
		self.app = app


	async def start(self) -> None:
		await self.app.startEvent()
		if self.autoclear:
			Ui().clear()

		while True:
			c = input("Chiori: ")
			await self.app.messageEvent(await self.convert(f"/{c}"))

	def setLevel(self, event: Event, c: Config) -> Event:
		event.model["level"] = 10
		return event

	async def convert(self, text: str) -> Event:
		event = Event()
		event.model["text"] = text
		return event

	async def message(self, event: Event, message: str, **params) -> None:
		"""Send message to target peer_id with parameters."""
		pront(message)


def main() -> None:
	app = Chio()
	parser = argparse.ArgumentParser()
	parser.add_argument("backend", help="ID движка для запуска",
						default=None, choices=["vk", "vku", "cli"])
	parser.add_argument("-c", "--config", help="Отобразить настройки",
						action="store_true")
	args = parser.parse_args()

	if args.config:
		app.c.print_config()

	if args.backend == "vk":
		app.backend = vk.VkGroup(app)

	elif args.backend == "vku":
		app.backend = vk.VkUser(app)

	elif args.backend == "cli":
		app.backend = Starter(app)

	load_plugins(app)
	app.start()


if __name__ == '__main__':
	main()
